package com.tanhua.server.controller;

import com.tanhua.domain.db.SoultestResult;
import com.tanhua.domain.vo.PaperLinkedVo;
import com.tanhua.domain.vo.SoulResultVo;
import com.tanhua.server.service.TestSoulService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Author Jyz
 * @Date 2021/8/23 - 11:53
 * @Description com.tanhua.server.controller
 * @Since version-11
 */
/*
灵魂测试控制层
 */
@RestController
@RequestMapping("/testSoul")
public class TestSoulController {

    @Autowired
    private TestSoulService testSoulService;

    /**
     * 展示测灵魂
     */
    @GetMapping
    public ResponseEntity testSoul(){
        List<PaperLinkedVo> list= testSoulService.testSoul();
        //返回试题数量
        return ResponseEntity.ok(list);
    }

    /**
     * 提交问卷
     * @param map
     * @return
     */
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity postMapper(@RequestBody Map<String, List<Map>> map){
        List<Map> answers = map.get("answers");
        //调用service 通过问题表查询问卷id
        String reportId  = testSoulService.postMapper(answers);
        //返回报告id
        return ResponseEntity.ok(reportId);
    }

    /**
     * 查看测试结果
     * @param id
     * @return
     */
    @GetMapping("/report/{id}")
    public ResponseEntity getReport(@PathVariable("id") Long id){
        SoulResultVo soulResultVo = testSoulService.getReport(id);
        //返回报告结果
        return ResponseEntity.ok(soulResultVo);
    }


}


